package 实验二;

import java.util.ArrayList;
import java.util.List;

public class Student {
    private String id;           // 编号
    private String name;         // 姓名
    private String gender;       // 性别
    private List<Course> selectedCourses; // 所选课程列表
    private String major;        // 所属专业

    public Student(String id, String name, String gender, String major) {
        this.id = id;
        this.name = name;
        this.gender = gender;
        this.selectedCourses = new ArrayList<>();
        this.major = major;
    }

    // 选课方法
    public void selectCourse(Course course) throws IllegalArgumentException {
        if (selectedCourses.contains(course)) {
            throw new IllegalArgumentException("学生已经选修该课程： " + course.getCourseName());
        }
        selectedCourses.add(course);
        System.out.println("学生" + name + "（编号：" + id + "）成功选修《" + course.getCourseName() + "》课程。");
    }

    // 退课方法
    public void dropCourse(Course course) throws IllegalArgumentException {
        if (!selectedCourses.contains(course)) {
            throw new IllegalArgumentException("学生未选修课程： " + course.getCourseName());
        }
        selectedCourses.remove(course);
        System.out.println("学生" + name + "（编号：" + id + "）退出《" + course.getCourseName() + "》课程。");
    }

    // 打印课表方法
    public void printCourseSchedule() {
        System.out.println("=== " + major + " 专业学生 " + name + "（编号：" + id + "）的课表 ===");
        if (selectedCourses.isEmpty()) {
            System.out.println("暂无选课记录。");
        } else {
            for (Course course : selectedCourses) {
                System.out.println("课程名称：" + course.getCourseName());
                System.out.println("上课地点：" + course.getLocation());
                System.out.println("时间：" + course.getTime());
                System.out.println("授课教师：" + course.getTeacher().getName());
            }
        }
        System.out.println("======================");
    }

    // getter 和 setter 方法
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getGender() { return gender; }
    public void setGender(String gender) { this.gender = gender; }
    public List<Course> getSelectedCourses() { return selectedCourses; }
    public void setSelectedCourses(List<Course> selectedCourses) { this.selectedCourses = selectedCourses; }
	public void setMajor(String major) { this.major = major; }
}

